package ysq.xyg.web.controller;

import cn.hutool.core.util.StrUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import ysq.xyg.base.aspect.BaseLog;
import ysq.xyg.base.controller.BaseController;
import ysq.xyg.base.model.dto.ReturnEntity;
import ysq.xyg.base.util.BaseConstant;
import ysq.xyg.web.model.po.WebArticle;
import ysq.xyg.web.model.vo.WebArticleVo;
import ysq.xyg.web.service.WebArticleService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 业务模块-文章controller层
 *
 * @author shengQiang yu
 * @date 2019-4-25 16:53:29
 */
@RestController
public class
WebArticleController extends BaseController {

    private static Logger log= LoggerFactory.getLogger(WebArticleController.class);
    @Resource
    private WebArticleService webArticleService;

    private WebArticle webArticle;

    /**
     * 获取下拉框集合
     *
     * @param code code值
     * @author shengQiang yu
     * @date 2019-4-25 16:49:54
     */
    @RequestMapping(value = "/webArticle/acceptSelect",method = RequestMethod.POST)
    public ReturnEntity acceptSelect(String code){
        return webArticleService.acceptSelect(code);
    }
    /**
     * 分页查询
     *
     * @param webArticleVo 对象
     * @param pageSize 展示数量
     * @param pageNum 当前页面
     * @author shengQiang yu
     * @date 2019-4-25 16:53:29
     */
    @BaseLog(module = "业务模块",className = "文章",methods = "分页查询",businessType = BaseConstant.SYS_BUSINESS_TYPE_GET,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/webArticle/page",method = RequestMethod.POST)
    public ReturnEntity page(WebArticleVo webArticleVo, int pageSize, int pageNum){
        ReturnEntity returnEntity = webArticleService.page(webArticleVo,pageSize,pageNum);
        return returnEntity;
    }

    /**
     * 跳转连接
     *
     * @param id 主键id
     * @author shengQiang yu
     * @date 2019-4-25 16:53:29
     */
    @RequestMapping(value = "/webArticle/getEntity",method = RequestMethod.GET)
    public ModelAndView getEntity(String id){
        ModelAndView view = new ModelAndView("/web/webArticleUpdateOrSave");
        if(StrUtil.isNotEmpty(id)){
            webArticle = webArticleService.selectByPrimaryKey(id);
            view.addObject("webArticle", webArticle);
        }
        return view;
    }
    /**
     * 删除
     *
     * @param id 主键id
     * @author shengQiang yu
     * @date 2019-4-25 16:53:29
     */
    @BaseLog(module = "业务模块",className = "文章",methods = "删除",businessType = BaseConstant.SYS_BUSINESS_TYPE_DELETE,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/webArticle/delete")
    public ReturnEntity delete(HttpServletRequest request,String id){
        return webArticleService.delete(id,acceptCurrentUser(request));
    }

    /**
     * 添加或修改
     *
     * @param webArticleVo Vo对象
     * @author shengQiang yu
     * @date 2019-4-25 16:53:29
     */
    @BaseLog(module = "业务模块",className = "文章",methods = "添加或修改",businessType = BaseConstant.SYS_BUSINESS_TYPE_UPDATE,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/webArticle/addOrUpdate",method = RequestMethod.POST)
    public ReturnEntity delete(HttpServletRequest request,WebArticleVo webArticleVo){
        return webArticleService.addOrUpdate(webArticleVo,acceptCurrentUser(request));
    }
}